package cn.cmvideo.springboot;

import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExchangerCase
{
	private static Exchanger<String> ex = new Exchanger<String>();
	
	private static ExecutorService service = Executors.newFixedThreadPool(2);
	
	public static void main(String[] args)
	{
		service.execute(new Runnable()
		{
			
			@Override
			public void run()
			{
				String a = "A";
				try
				{
//					ex.exchange("BBBB");
					ex.exchange(a);
				} catch (InterruptedException e)
				{
					e.printStackTrace();
				}
				
			}
		});
		
		service.execute(new Runnable()
		{
			
			@Override
			public void run()
			{
				String b = "B";
				try
				{
					String a = ex.exchange(b);
					System.out.println("a = " + a);
					System.out.println("b = " + b);
					System.out.println(a.equalsIgnoreCase(b));
				} catch (InterruptedException e)
				{
					e.printStackTrace();
				}
				
			}
		});
		
		service.shutdown();
	}

}
